package com.atguigu.stgy.app.controller;

import com.atguigu.stgy.app.service.ViewAppointmentService;
import com.atguigu.stgy.common.exception.StgyException;
import com.atguigu.stgy.common.interceptor.StgyAuthInterceptor;
import com.atguigu.stgy.model.entity.ViewAppointment;
import com.atguigu.stgy.model.result.R;
import com.atguigu.stgy.model.result.ResultCodeEnum;
import com.atguigu.stgy.model.vo.AppointmentDetailVO;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app/appointment")
public class ViewAppointmentController {
    /*
    {
      "id": "",
      "name": "longge",
      "phone": "13566666666",
      "apartmentId": "10",
      "appointmentTime": "2024-06-10 12:18:15",
      "additionalInfo": "wrerewr",
      "appointmentStatus": 1,
        userid
    }
     */
    @Resource
    ViewAppointmentService viewAppointmentService;
    ///app/appointment/getDetailById
    @Operation(summary = "查看看房预约详情")
    @GetMapping("getDetailById")
    public R<AppointmentDetailVO> getDetailById(@RequestParam("id")Long id){
        //查询当前用户的看房预约列表，按照时间降序排列
        return R.ok(viewAppointmentService.getDetailById(id));
    }
    ///app/appointment/saveOrUpdate
    @Operation(summary = "保存看房预约信息")
    @PostMapping("saveOrUpdate")
    public R saveOrUpdate(@RequestBody ViewAppointment viewAppointment){
        viewAppointment.setUserId(StgyAuthInterceptor.THREAD_LOCAL.get());
        boolean b = viewAppointmentService.saveOrUpdate(viewAppointment);
        if(!b){
            throw new StgyException(ResultCodeEnum.FAIL);
        }
        return R.ok();
    }
    ///app/appointment/listItem
    @Operation(summary = "查看看房预约信息列表")
    @GetMapping("listItem")
    public R<List<ViewAppointment>> listItem(){
        //查询当前用户的看房预约列表，按照时间降序排列
        return R.ok(viewAppointmentService.listItem());
    }


}
